package com.smh.a03exerciseDemo1;

import java.io.*;

public class Test1 {
    public static void main(String[] args) throws IOException {


        //拷贝文件夹
        File file = new File("day26-code\\file\\asd");

        File file1 = new File("day26-code\\file\\qwe");

        method(file, file1);

    }

    public static void method(File file, File file1) throws IOException {
        if (file.isFile()) {
            FileInputStream fis = new FileInputStream(file.getPath());
            FileOutputStream fos = new FileOutputStream(file1.getPath());

            byte[] bytes = new byte[1024 * 1024];
            int len;
            while ((len = fis.read()) != -1) {
                fos.write(bytes, 0, len);
            }
            fos.close();
            fis.close();
        } else {
            file1.mkdir();
            File[] files = file.listFiles();
            for (File file2 : files) {
                File file3 = new File(file1.getPath(), file2.getName());
                method(file2, file3);
            }
        }
    }

}
